package rs.dalao.syc.user.all.controller;/*
 *   @author:Casin
 *   @date:2023/8/12
 *   @code:
 */


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import rs.dalao.syc.common.pojo.authentication.CurrentPrincipal;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.common.response.JsonResult;
import rs.dalao.syc.user.all.pojo.vo.PrescriptionListVO;
import rs.dalao.syc.user.all.service.IPrescriptionService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/user/prescription")
@Api(tags = "1. 我的处方")
@Slf4j
public class PrescriptionController {
    @Autowired
    IPrescriptionService service;
    @GetMapping("/list")
    @ApiOperation("获取处方信息")
    @PreAuthorize("hasAuthority('/user/prescription/list')")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "2", dataType = "long")
    })
    public JsonResult getPatientList(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,Integer page){
        Long userId = currentPrincipal.getId();
        log.debug("开始处理【查询用户列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<PrescriptionListVO> pageData = service.getPrescriptionByUserId(userId,pageNum);
        return JsonResult.ok(pageData);
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("在用户病患管理中删除用户列表")
    @PreAuthorize("hasAuthority('/user/prescription/list')")
    @ApiOperationSupport(order = 100)
    public JsonResult delete(@PathVariable @Range(min = 1, message = "请提交有效的类别ID值！") Long id) {
        service.update(id);
        return JsonResult.ok();
    }

}
